import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;

public class SQLQueryThread extends Thread {
	private SQLDatabase sql;

	private SynchQueue queue;

	public SQLQueryThread(SQLDatabase sql, SynchQueue queue) {
		this.sql = sql;
		this.queue = queue;
	}

	public Connection connect() throws Exception {
		String serverName = "172.16.5.1";
		String mydatabase = "cs2";
		String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a
		// JDBC
		// url
		String username = "cs2";
		String password = "cs2";
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		Connection connection = DriverManager.getConnection(url, username,
				password);
		return connection;
	}

	public void run(){
		Connection connection = null;
		try {
			connection = connect();
			ArrayList stuff = sql.EntityData();
		} catch (Exception e) {
			System.out
					.print("SQL database could not load or connection could not be established.");
			e.printStackTrace();
		}
		while (true) {
			try {
				if (!queue.isEmpty() && connection != null) {
					String blah = (String) queue.dequeue();
					if (blah.equals("get")) {

					} else {
						Statement stmt = connection.createStatement();
						stmt.executeUpdate(blah);
					}
				}
			} catch (Exception e) {
				System.out.println(e);
			}
		}
	}
}
